#!/bin/bash

eeprom_path="/sys/bus/i2c/devices/6-0050/eeprom"
eeprom_data1="          "
eeprom_data2="R1000-TEST"

sudo chmod 777 $eeprom_path

# 写入1
echo "$eeprom_data1" > $eeprom_path

# 读取 EEPROM 文件内容并检查是否包含 data1 数据
cat $eeprom_path | hexdump -C | grep "$eeprom_data1"
status=$?

# 根据 status 的值输出相应的消息
if [ $status -eq 0 ]; then
  echo "EEPROM Write1 and Read1 OK"
#  exit 0
else
  echo "EEPROM Write1 or Read1 FAIL"
  exit 1
fi

sleep 0.5

# 写入 EEPROM 数据2
echo "$eeprom_data2" > $eeprom_path

# 读取 EEPROM 文件内容并检查是否包含 data2 数据
cat $eeprom_path | hexdump -C | grep "$eeprom_data2"
status=$?

# 根据 status 的值输出相应的消息
if [ $status -eq 0 ]; then
  echo "EEPROM Write2 and Read2 OK"
  exit 0
else
  echo "EEPROM Write2 or Read2 FAIL"
  exit 1
fi
